home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
234_01
/
xdir.c
< prev
next >
Wrap
Text File
|
1987-06-16
|
18KB
|
700 lines
/*
HEADER: CUG nnn.nn;
TITLE: XDIR - Hard Disk Manager
VERSION: 1.0 for IBM-PC
DATE: Apr 03, 1987
DESCRIPTION: Hard Disk Manager for IBM PC
KEYWORDS: Hard Disk Manager Dump Directory
SYSTEM: IBM-PC and Compatiables
FILENAME: xdir.C
WARNINGS: None
CRC: N/A
SEE-ALSO: HDIR.DOC and XDIR.DOC
AUTHOR: Mike Blakley 15645 SW 82 Cir Ln #76, Miami, Fl 33193
COMPILERS: ECO-C
REFERENCES: XDIR.DOC
*/
/*
xdir.c
Superwash
to process the DOS directories
*/
#include "hdir.doc" /* program documentation */
#include "stdio.h"
#include "dos.h"
#include "dir.h"
#include "xdir.h"
struct tdir *pnam[MAXDIR]; /* directory entries */
struct tdir *fnam[MAXFILE]; /* file names */
char cdir[PATHSIZ]; /* current directory */
char helpfile[PATHSIZ] = "xdir.doc"; /* name of helpfile */
unsigned cdate; /* comparison date */
/*
process DOS directories
*/
main(argc,argv)
int argc; /* argument count */
char **argv; /* argument values */
{
int strcmp(char *,char *);
void dironly(char **buffer, int type,int level);
void update (char **buffer, int type,int level);
char *strdsave(struct direct *, char *root);
char *alloc(int amt);
int i,j;
char answer[MAXFILE]; /* for responses */
char srmask[15]; /* search mask */
int att; /* attribute search */
struct tdir *tp;
static int pcount, fcount;
int cf,ct; /* flag for see files */
char work[20]; /* work area selected dir */
static int firstime = 0; /* for command line directory */
char c,temp[20]; /* debug */
if (argc == 2) /* process command line args */
{
if (strcmp(argv[1],"help") == 0) typ(helpfile);
if (strcmp(argv[1],"-v") == 0) ;
}
else if (argc == 1)
{
i = help(); /* display help message */
if (i == 1) typ(helpfile);
}
pcount = bildir(); /* build path array */
qksort(pcount,pcomp,pswap); /* sort by path name */
if (argc == 2) /* test command line directory */
{
strcpy(work,argv[1]);
j = testdir(work,pcount);
if (j < 0) firstime = 0;
else
{
firstime = 1;
strcpy(cdir,work);
clear(answer,MAXFILE,' ');
answer[j] = 'S';
}
}
while (1) /* main loop */
{
if (firstime) firstime = 0;
else
{
clear(answer,MAXFILE,' '); /* clear answers */
disx(pnam,pcount,answer,1); /* ask what directory <=== */
}
for (i=ct=0;i<MAXFILE;i++) /* get directory selection */
{
if (answer[i] == 'S') /* selection criteria */
{
++ct;
tp = pnam[i];
strcpy(cdir,tp->d_name); /* note current directory */
if (cdir[0] == 0) strcpy(cdir,"**ROOT**");
break;
}
}
if (ct == 0) break; /* nothing selected */
while (1) /* get search criteria */
{
j = criteria(srmask,&att,&cf);
if (j) break;
}
fcount = bilfil(pnam[i],srmask,cdate,att); /* build file names array */
if (fcount == 0)
{
xmsg("No entries selected - press any key ");
continue;
}
if (fcount == -1)
{
xmsg("Couldn't allocate memory ");
break;
}
switch (cf) /* determine sort method */
{
case 'D':
qksort(fcount,fcompd,fswap);
break;
case 'S':
qksort(fcount,fcomps,fswap);
break;
default:
qksort(fcount,fcomp,fswap); /* sort alpha on file names */
break;
}
if ((cf == 'Y') || (cf == 'D') || (cf == 'S') || (cf == 'A'))
dfnam(fcount,cdir); /* display files */
clear(answer,MAXFILE,' ');
disx(fnam,fcount,answer,2); /* ask what files */
for (i=ct=0;i<MAXFILE;i++) /* count responses */
if (answer[i] != ' ') ++ct;
if (ct) action(answer,pcount); /* process answer */
for (i=0;i<fcount;i++) free(fnam[i]); /* free storage */
clrscr();
cursor(5,10);
writestr("Processing completed - enter next directory name ");
cursor(6,10);
writestr("Press ENTER for root directory, ESC to end ");
c = getch();
if (c == 27) break;
if (c == 13) work[0] = 0;
else
{
putchar(c);
gets(temp);
work[0] = c;
work[1] = 0;
strcat(work,temp);
}
j = testdir(work,pcount);
if (j < 0) firstime = 0;
else
{
firstime = 1;
strcpy(cdir,work);
clear(answer,MAXFILE,' ');
answer[j] = 'S';
}
} /* end while 1 processing */
clrscr();
}
/*
action
take the requested action
*/
void action(answer,pcount)
char *answer;
int pcount;
{
static int i,j,k,l,c;
int rc; /* return code from delete */
char filename[80]; /* used in rename and copy */
struct tdir *tp, *fp;
int row;
char key[30]; /* encryption key */
static int dflag; /* flag for display */
int copybulk = 0; /* no bulk copy */
char bulkname[80]; /* bulk file name */
int found; /* found flag for search of paths */
char workname[80]; /* work area for file name */
dflag = 1; /* indicate need for screen display */
for (i=0;i<MAXFILE;i++)
{
tp = fnam[i];
j = (int) answer[i];
switch (j)
{
case 'T': /* list a file to console */
typ(tp->d_path);
dflag = 1; /* indicate new display required */
break;
case 'L': /* list file to printer */
clrscr();
writestr(" File ");
writestr(tp->d_path);
writestr(" will be listed to the printer ");
lis(tp->d_path);
break;
case 'C': /* copy file */
if (copybulk) /* bulk copy no questions */
{
strcpy(filename,bulkname);
strcat(filename,"\\");
strcat(filename,tp->d_name);
xcopy(tp->d_path,filename);
break;
}
dscr(); /* display the screen */
row = 4;
cursor(row++,20);
writestr("Copy from file ");
writestr(tp->d_path);
writestr(" to ? ");
gets(filename);
if (strlen(filename) == 0) break;
for (l=0,k=strlen(filename);l<k;l++)
filename[l] = toupper(filename[l]);
if (filename[0] != '\\')
{
cvp(tp->d_path,workname);
strcat(workname,"\\");
strcat(workname,filename);
strcpy(filename,workname); /* build output name */
}
else
{
for (l=found=0;l<pcount;l++) /* see if a path */
{
fp = pnam[l];
k = strcmp(fp->d_path,filename);
if (k == 0) found = 1;
}
if (found == 1)
{
cursor(row++,20);
writestr("Desire bulk copy? (Y)es (N)o ");
c = toupper(getch());
if (c == 'Y')
{
copybulk = 1;
strcpy(bulkname,filename);
strcat(filename,"\\");
strcat(filename,tp->d_name);
xcopy(tp->d_path,filename);
}
}
}
xcopy(tp->d_path,filename); /* copy the file */
break;
case 'R': /* rename the file */
dscr(); /* display t